☰ See All Chapters |
JavaScript ES6 Template Literals
String created using backtick supports interpolation, means if you place a variable within the backtick string, it returns the value of that variable. You can place the variable name using interpolation syntax ${variableName} as below example.
var name = 'Advith'; var age = 4; console.log(`hello my name is ${name}, and I am ${age} years old`); |

The ${} works fine with any kind of expression, including member expressions and method calls.
var name = 'Advith'; var age = 4; console.log(`hello my name is ${name.toUpperCase()}, and I am ${age / 2} years old`); |

All Chapters